﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Management.HyperV.Model.Msvm;

namespace System.Management.HyperV.Tests
{
    [TestClass]
    public class Test_Properties
    {
        [TestMethod]
        public void Test_Properties_ComputerSystem()
        {
            using (var searcher = new ManagementObjectSearcher(@"root\virtualization", "SELECT * FROM Msvm_ComputerSystem WHERE Caption = 'Virtual Machine'"))
            {
                var vmList = from mo in searcher.Get().OfType<ManagementObject>()
                             select new ComputerSystem(mo);

                foreach (var vm in vmList)
                {
                    // Msvm_ComputerSystem Properties:
                    Assert.IsTrue(vm.OnTimeInMilliseconds >= 0);
                    Assert.IsTrue(vm.ProcessID >= 0);
                    Assert.IsNotNull(vm.TimeOfLastConfigurationChange);

                    Assert.IsNull(vm.Dedicated);
                    Assert.IsNull(vm.IdentifyingDescriptions);
                    Assert.IsNull(vm.OtherDedicatedDescriptions);
                    Assert.IsNull(vm.OtherIdentifyingInfo);
                    Assert.IsNull(vm.PowerManagementCapabilities);
                    Assert.IsTrue(vm.ResetCapability == 1);

                    Assert.AreEqual<string>(vm.CreationClassName, "Msvm_ComputerSystem");
                    Assert.IsNull(vm.NameFormat);
                    Assert.IsNull(vm.PrimaryOwnerContact);
                    Assert.IsNull(vm.PrimaryOwnerName);
                    Assert.IsNull(vm.Roles);

                    Assert.AreEqual<ushort>(vm.EnabledDefault, 2);
                    Assert.AreEqual<ushort>(vm.EnabledState, 32769);
                    Assert.IsNull(vm.OtherEnabledState);
                    Assert.AreEqual<ushort>(vm.RequestedState, 12);
                    Assert.IsNotNull(vm.TimeOfLastStateChange);

                    Assert.AreEqual<ushort>(vm.HealthState, 25);
                    Assert.IsNull(vm.InstallDate);
                    Assert.IsNotNull(vm.Name);
                    Assert.IsTrue(vm.OperationalStatus.Length > 0);
                    Assert.IsNull(vm.Status);
                    Assert.IsTrue(vm.StatusDescriptions.Length > 0);

                    Assert.IsNotNull(vm.ElementName);
                    Assert.AreEqual<string>(vm.Caption, "Virtual Machine");
                    Assert.AreEqual<string>(vm.Description, "Microsoft Virtual Machine");

                    Assert.IsNotNull(vm.__CLASS);
                    Assert.IsNotNull(vm.__DERIVATION);
                    Assert.IsNotNull(vm.__DYNASTY);
                    Assert.IsNotNull(vm.__GENUS);
                    Assert.IsNotNull(vm.__NAMESPACE);
                    Assert.IsNotNull(vm.__PATH);
                    Assert.IsNotNull(vm.__PROPERTY_COUNT);
                    Assert.IsNotNull(vm.__RELPATH);
                    Assert.IsNotNull(vm.__SERVER);
                    Assert.IsNotNull(vm.__SUPERCLASS);
                }
            }

        }
    }
}
